﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;

namespace YinLongTool.Pc
{
    public class ComputerInfoGetter
    {
        public static string GetMAC()
        {
            string text = "";
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
            foreach (ManagementObject item in managementObjectCollection)
            {
                if (item["IPEnabled"].ToString() == "True")
                {
                    if (text.Length > 0)
                    {
                        text += "\n";
                    }
                    text += item["MacAddress"].ToString();
                }
            }
            return text;
        }

        public static string GetCpuId()
        {
            try
            {
                ManagementObjectCollection instances = new ManagementClass("Win32_Processor").GetInstances();
                string result = null;
                using (ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator = instances.GetEnumerator())
                {
                    if (managementObjectEnumerator.MoveNext())
                    {
                        ManagementObject managementObject = (ManagementObject)managementObjectEnumerator.Current;
                        result = managementObject.Properties["ProcessorId"].Value.ToString();
                    }
                }
                return result;
            }
            catch
            {
                return "strCpuID";
            }
        }
    }
}
